$(function() {
			getData();
});

var treg;
function getData(v) {
	treg = $('#datagrid_list').treegrid({
		idField : 'id',
		toolbar : "#toolbar",
		treeField : 'mc',
		title : '语料库',
		url : '${ctx}/sys/nlp/listcode',
		fit : true,
		loadMsg : '数据加载中...',
		pageSize : 10,
		pagination : false,
		pageList : [10, 20, 30],
		sortOrder : 'asc',
		rownumbers : true,
		singleSelect : true,
		fitColumns : true,
		showFooter : true,
		frozenColumns : [[]],
		columns : [[{
					field : 'id',
					title : '编号',
					hidden : true
				}, {
					field : 'name',
					title : '菜单名称'
				}, {
					field : 'url',
					title : '菜单地址',
					formatter : function(v, r) {
						return "<div title='" + v + "'>" + cmm.strLen(v, 20)
								+ "</div>";
					}
				}, {
					field : 'sort',
					title : '菜单顺序'
				}, {
					field : 'sn',
					title : "权限符"
				}, {
					field : 'pid',
					title : '操作',
					width : 100,
					formatter : function(value, rec, index) {
						var href = '';
						href += "[<a href='#' onclick=del('" + rec.id + "','"
								+ value + "')>";
						href += "删除</a>]";
						href += "[<a href='#' onclick=update('" + rec.id
								+ "','" + value + "')>";
						href += "修改</a>]";
						return href;
					}
				}]],
		onBeforeExpand : function(row) {
			if (row) {
				$("#datagrid_list").treegrid("options").url = basePath
						+ "/adx/sys/getfunc";
			}
		},
		onLoadSuccess : function(data, row) {
			$("#datagrid_list").treegrid("clearSelections");
		},
		onClickRow : function(rowData) {
			rowid = rowData.id;
			gridname = 'datagrid_list';
		}
	});
	/*
	 * $('#datagrid_list').treegrid('getPager').pagination({ beforePageText :
	 * '', afterPageText : '/{pages}', displayMsg : '{from}-{to}共{total}条',
	 * showPageList : true, showRefresh : true });
	 * $('#datagrid_list').treegrid('getPager').pagination({ onBeforeRefresh :
	 * function(pageNumber, pageSize) { $(this).pagination('loading');
	 * $(this).pagination('loaded'); } });
	 */
}
function opter() {
	removeText("add");
	cmm.openDialog("#dd", {
				name : "添加",
				callback : function(v) {
					var ddt = $(v);
					if (!$("#ff").form("validate")) {
						return false;
					} else {
						ddt.linkbutton("disable");
						$.post(basePath + "/adx/sys/addfunc", $("#ff")
										.formSerialize(), function(data) {

									ddt.linkbutton("enable");
									if (data != null
											&& data.statusCode == "200") {
										$("#dd").dialog("close");
										treeRefresh("funtree1");
										treeRefresh("tree1");
										// $("#datagrid_list").treegrid("options").url=basePath
										// + '/adx/sys/listfunc';
										treeDatasynAdd();
									}
								}, 'json')
					}
				}
			});
}

function removeText(v) {
	if (v == "add") {
		$("#ff input").each(function() {
					var tt = $(this);
					if (tt.attr("name") == "sort" || tt.attr("id") == "sort") {
						// tt.numberspinner("setValue", 100);
					} else {
						$(this).val('');
					}
				});
		$("#ismenu").combobox("setValue", "1");
	} else {

	}
}